package com.krui.iweibo.utils.emotion;

import java.util.HashMap;

import android.R.integer;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.krui.iweibo.R;
import com.krui.iweibo.app.IweiboApplication;

public class EmotionParse {
	
	public Context context;
	/** 保存表情名字跟ID*/
	public HashMap<String, Integer> emotionsMap;
	/** 表情名*/
	public String[] emotionNames;
	
	
	public EmotionParse(){
		this.context = IweiboApplication.context;
		emotionNames = context.getResources().getStringArray(R.array.defualt_emotions);
		
		if(emotionNames.length != IDs.ids.length)
			throw new IllegalStateException("长度不等");
		
		int len = emotionNames.length;
		
		
		emotionsMap = new HashMap<String, Integer>(len);
		
		for(int i = 0; i < len; i++){
			emotionsMap.put(emotionNames[i], IDs.ids[i]);
		}
	}
	
	
	/**
	 * 根据表情别名匹配表情
	 * @param phrse
	 * @return
	 */
	public Drawable getEmotionByPhrse(String phrse){
		
		Integer id = emotionsMap.get(phrse);
		
		if (id != null) {
			return context.getResources().getDrawable(id);
		}
		
		return null;
	}
	
	
	

}
